Skip to content

Commit

Permalink
Make relative path for animated filenames while saving
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwarthog authored and morevnaproject committed Mar 28, 2015
1 parent 08b5a8b commit c5850b8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions synfig-studio/src/synfigapp/instance.cpp
Expand Up @@ -458,6 +458,44 @@ Instance::embed_all() {
return success;
}

//! make relative filenames from animated valuenodes
void Instance::convert_animated_filenames(const Canvas::Handle &canvas, const synfig::String &old_path, const synfig::String &new_path)
{
for(Canvas::iterator i = canvas->begin(); i != canvas->end(); ++i)
{
const Layer::DynamicParamList &dynamic_param_list = (*i)->dynamic_param_list();
Layer::DynamicParamList::const_iterator j = dynamic_param_list.find("filename");
if (j != dynamic_param_list.end())
{
ValueNode_Animated::Handle valuenode_animated = ValueNode_Animated::Handle::cast_dynamic(j->second);
if (valuenode_animated)
{
WaypointList &waypoint_list = valuenode_animated->editable_waypoint_list();
for(WaypointList::iterator k = waypoint_list.begin(); k != waypoint_list.end(); ++k)
{
ValueNode_Const::Handle valuenode_const = ValueNode_Const::Handle::cast_dynamic(k->get_value_node());
if (valuenode_const && valuenode_const->get_type() == type_string)
{
String s = valuenode_const->get_value().get(String());
if (!s.empty() && s[0] != '#')
{
warning(old_path);
warning(new_path);
if (!is_absolute_path(s) && !old_path.empty()) s = old_path + ETL_DIRECTORY_SEPARATOR + s;
s = relative_path(new_path, s);
valuenode_const->set_value(s);
}
}
}
}
}

etl::handle<Layer_PasteCanvas> layer_paste_canvas = etl::handle<Layer_PasteCanvas>::cast_dynamic(*i);
if (layer_paste_canvas && layer_paste_canvas->get_sub_canvas() && !layer_paste_canvas->get_sub_canvas()->is_root())
convert_animated_filenames(Canvas::Handle(layer_paste_canvas->get_sub_canvas()), old_path, new_path);
}

}

bool
Instance::save()
Expand All @@ -475,6 +513,8 @@ Instance::save_as(const synfig::String &file_name)
bool extract_data = false;
std::string canvas_filename = file_name;

convert_animated_filenames(get_canvas(), absolute_path(get_canvas()->get_file_path()), absolute_path(dirname(file_name)));

// save bitmaps
std::set<Layer::Handle> layers_to_save_set;
for(std::list<Layer::Handle>::iterator i = layers_to_save.begin(); i != layers_to_save.end(); i++)
Expand Down
2 changes: 2 additions & 0 deletions synfig-studio/src/synfigapp/instance.h
Expand Up @@ -148,6 +148,8 @@ class Instance : public Action::System , public CVSInfo

bool embed_all();

void convert_animated_filenames(const synfig::Canvas::Handle &canvas, const synfig::String &old_path, const synfig::String &new_path);

//! Saves the instance to filename_
bool save();

Expand Down

0 comments on commit c5850b8

Please sign in to comment.